//
//  SCHeaderCollectionView.m
//  OurMoon
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCHeaderCollectionView.h"
#import "SCHeaderCollectionViewCell.h"
#import "NightHeader.h"
#import "FitHeader.h"
@implementation SCHeaderCollectionView

- (instancetype)initWithFrame:(CGRect)frame WithType:(SCCollectionViewKind)kind
{
    self = [super initWithFrame:frame];
    if (self) {
        //获取头视图View种类
        _kind = kind;
        //初始化flowLayout
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        if (_kind == SCCollectionViewFlowLayoutByVideo) {
            flowLayout.itemSize = CGSizeMake(92 * FitWidth, 87 * FitHeight);
            flowLayout.minimumLineSpacing = 0.5 * FitHeight;
            flowLayout.minimumInteritemSpacing = 0.5 * FitWidth;
            flowLayout.sectionInset = UIEdgeInsetsMake(5 * FitWidth, 0.5 * FitHeight, 0.5 * FitWidth, 0.5 * FitHeight);
        }
        if (_kind == SCCollectionViewFlowLayoutByRadio) {
            flowLayout.itemSize = CGSizeMake(375 * FitWidth, 40 * FitHeight);
            flowLayout.minimumLineSpacing = 1 * FitHeight;
            flowLayout.minimumInteritemSpacing = 1 * FitHeight;
            flowLayout.sectionInset = UIEdgeInsetsMake(1 * FitWidth, 1 * FitHeight, 1 * FitWidth, 1 * FitHeight);
        }
        
        //初始化collectionView
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:flowLayout];
        //设置代理
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        //设置整页滚动
        _collectionView.pagingEnabled = YES;
        //
        [_collectionView NightWithType:UIViewColorType2];
        [self addSubview:_collectionView];
        
        [_collectionView registerClass:[SCHeaderCollectionViewCell class] forCellWithReuseIdentifier:@"identifier"];
    }
    return self;
}

- (void)setDataVideoSidListArray:(NSMutableArray *)dataVideoSidListArray
{
    _dataVideoSidListArray = dataVideoSidListArray;
    [_collectionView reloadData];
}
- (void)setDataVideoListArray:(NSMutableArray *)dataVideoListArray
{
    _dataVideoListArray = dataVideoListArray;
    [_collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (_kind == SCCollectionViewFlowLayoutByVideo) {//视频
        return _dataVideoSidListArray.count;
    }
    else{//电台
        return 1;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    SCHeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identifier" forIndexPath:indexPath];
    [cell NightWithType:UIViewColorTypeNormal];
    //视频
    if (_kind == SCCollectionViewFlowLayoutByVideo) {
        [cell getkind:SCHeaderCollectionViewCellByVideo];
        cell.videoSidListModel = _dataVideoSidListArray[indexPath.row];
    }
    //电台
    else{
        [cell getkind:SCHeaderCollectionViewCellByRadio];
        //cell.radioStr = _dataVideoListArray[indexPath.row];
        cell.radioStr = @"最近播放";
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //视频
    if (_kind == SCCollectionViewFlowLayoutByVideo) {
        [self.delegate HeaderViewControllerByVideoJump:_dataVideoSidListArray[indexPath.row]];
    }
    //电台
    else{
        [self.delegateRadio HeaderViewControllerByRadioJump:_dataVideoListArray[indexPath.row]];
    }
}

@end
